// Copyright 2021 Guoyoko. All Rights Reserved.

#include "SWGameViewportClientModule.h"
#include "Modules/ModuleManager.h"
#include "..\Public\SWGameViewportClientModule.h"
#include "Misc/ConfigCacheIni.h"


void FSWEditorViewportClientModule::StartupModule()
{
	/*-> Specify which Engine Default Class to use*/
	static const FString DefaultEnginePath = FString::Printf(TEXT("%sDefaultEngine.ini"), *FPaths::SourceConfigDir());
	GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("GameEngine"), TEXT("/Script/SWEditorViewportClient.SWGameEngine"), DefaultEnginePath);
	GConfig->SetString(TEXT("/Script/Engine.Engine"), TEXT("GameViewportClientClassName"), TEXT("/Script/SWEditorViewportClient.SWGameViewportClient"), DefaultEnginePath);

	GConfig->Flush(false, DefaultEnginePath);
}

void FSWEditorViewportClientModule::ShutdownModule()
{
	FString tmp(FCommandLine::Get());
	if(tmp.Contains(TEXT("-run=cook")))
	{
		return;
	}
	/*-> Remove specify Engine Default Class */
	if (GIsEditor)
	{
		static const FString DefaultEnginePath = FString::Printf(TEXT("%sDefaultEngine.ini"), *FPaths::SourceConfigDir());
		GConfig->RemoveKey(TEXT("/Script/Engine.Engine"), TEXT("GameEngine"), DefaultEnginePath);
		GConfig->RemoveKey(TEXT("/Script/Engine.Engine"), TEXT("GameViewportClientClassName"), DefaultEnginePath);

		GConfig->Flush(false, DefaultEnginePath);
	}

}


IMPLEMENT_MODULE(FSWEditorViewportClientModule, SWEditorViewportClient);
